package com.zyh.homework.test1;

import com.zyh.homework.test1.bean.Rectangle;

import java.util.Arrays;
import java.util.Random;

public class Test {
    public static void main(String[] args) {
        Rectangle[] re = new Rectangle[5];
        Random random = new Random();
        Rectangle rectangle1 = new Rectangle(random.nextDouble(9.9)+1,random.nextDouble(9.9)+1);
        Rectangle rectangle2 = new Rectangle(random.nextDouble(9.9)+1,random.nextDouble(9.9)+1);
        Rectangle rectangle3 = new Rectangle(random.nextDouble(9.9)+1,random.nextDouble(9.9)+1);
        Rectangle rectangle4 = new Rectangle(random.nextDouble(9.9)+1,random.nextDouble(9.9)+1);
        Rectangle rectangle5 = new Rectangle(random.nextDouble(9.9)+1,random.nextDouble(9.9)+1);

        re[0]=rectangle1;
        re[1]=rectangle2;
        re[2]=rectangle3;
        re[3]=rectangle4;
        re[4]=rectangle5;
        printArray(re);
        System.out.println("--------------------");
        System.out.println("面积从小到大排序如下：");
//        冒泡排序
        for (int i = 0; i < re.length-1; i++) {
            for (int j = 0; j < re.length-1-i; j++) {
                if (re[j].getArea()>re[j+1].getArea()){
                    Rectangle temp=re[j];
                    re[j]=re[j+1];
                    re[j+1]=temp;
                }
            }
        }
        printArray(re);
    }
    public static void printArray(Rectangle[] re){
        for (int i = 0; i < re.length; i++) {
            System.out.println("长："+re[i].getChang()+"宽："+re[i].getKuan()+"面积："+re[i].getArea()+"周长："+re[i].getPerimeter());
        }
    }
}
